'''
实验名称：超声波测距实验
接线说明：HC-SR04超声波模块-->ESP32 IO
        (VCC)-->(5V)
        (Trig)-->(4)
        (Echo)-->(27)
        (GND)-->(GND)
'''

from machine import Pin
import time
from hcsr04 import HCSR04

# 创建HCSR04的类，并将Trig引脚设为4，Echo引脚设为27
hcsr04 = HCSR04(trigger_pin = 4, echo_pin = 27)

if __name__ == "__main__":
    while True:
        # 调用distance_cm测量以厘米为单位的距离值
        distance = hcsr04.distance_cm()
        # 通过串口打印出数据，并延时0.5秒
        print("distance=%.2fCM" %distance)
        time.sleep(0.5)
